package com.iisigroup.project.statistics.job;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Set;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.ArrayUtils;

import com.iisigroup.project.statistics.ClassEval;
import com.iisigroup.project.statistics.model.Function;

import tw.gov.moi.ae.batch.sris.annotation.RisJob;
import tw.gov.moi.rl.job.Rl08f37Job;

public class JobStatCommonBase {

    /**
     * @param args
     */
    public static void main(String[] args) {
       final  Class<Rl08f37Job> clazz = Rl08f37Job.class ;
       final Function func =  extractJobInfo(clazz);
       System.out.println(ToStringBuilder.reflectionToString(func));
       
    }
    public static Function extractJobInfo (final Class<?> clazz ){        
        final  Annotation annotation = clazz.getAnnotation(RisJob.class);
        if(annotation != null ){
            final  RisJob  risjob =    (RisJob) annotation ;
            String functionName =  risjob.jobCode();
            String functionChtName =   risjob.jobName();
            final Function result = new Function();
            
            result.setFunctionChtName(functionChtName);
            result.setFunctionName(functionName);
            final ClassEval classEval = new ClassEval();
            
            final Set<String> importClass = classEval.getImportClass(clazz);
            result.setServiceImportedClassNames(importClass.toArray(new String[]{}));
            final Class<?>[] interfaces = clazz.getInterfaces();
            if(ArrayUtils.isNotEmpty(interfaces)){
                result.setServiceInterfaces(interfaces);
            }
        
            result.setServiceNames(new String[]{clazz.getSimpleName()});
            
            return result ; 
        }
        return null;
    }

}
